﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BBCP.Model;

namespace BBCP.UI.Tasks
{
    public class SellSummary : ITask
    {
        public bool Run()
        {
            using (NorthwindEntities context = new NorthwindEntities())
            {
                var query = context.Employees.Select(n => new
                {
                    Employee = n,
                    Turnower = n.Orders.Sum(m => m.Order_Details.Sum
                        (k => k.UnitPrice * k.Quantity)),
                    Cities = n.Territories.Select(m => m.TerritoryDescription).Distinct()
                });
                foreach (var item in query)
                {
                    Console.WriteLine("{0}\t{1}\t{2}",
                        item.Employee.EmployeeID,
                        item.Employee.LastName,
                        item.Turnower);
                    foreach (var items in item.Cities)
                    {
                        Console.WriteLine(items.ToString());
                    }
                    Console.WriteLine();
                }
            }
            return true;
        }
    }
}
